package com.example.test1;



import android.content.Intent;
import android.media.Image;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;

import android.support.v4.app.ListFragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.test1.adapter.VpAdapter;
import com.example.test1.fragment.CollectFragment;
import com.example.test1.fragment.ListsFragment;
import com.umeng.socialize.UMShareAPI;

import org.w3c.dom.Text;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

public class Main3Activity extends AppCompatActivity {

    @BindView(R.id.vp)
    ViewPager mVp;
    @BindView(R.id.tab)
    TabLayout mTab;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        ButterKnife.bind(this);
        ArrayList<Fragment> fragments = new ArrayList<>();
        fragments.add(new ListsFragment(this));
        fragments.add(new CollectFragment());
        ArrayList<String> titles = new ArrayList<>();
        titles.add("新闻");
        titles.add("收藏");

        VpAdapter vpAdapter = new VpAdapter(getSupportFragmentManager(),fragments,titles);
        mVp.setAdapter(vpAdapter);
        mTab.setupWithViewPager(mVp);
        for (int i = 0; i <titles.size() ; i++) {
            TabLayout.Tab tabAt = mTab.getTabAt(i);
            View inflate = LayoutInflater.from(this).inflate(R.layout.tablayout, null, false);
            ImageView iv = inflate.findViewById(R.id.tab_iv);
            TextView tv = inflate.findViewById(R.id.tab_tv);
            tabAt.setCustomView(inflate);
            tv.setText(titles.get(i));
            if (i==0){
                iv.setBackgroundResource(R.drawable.select1);
            }else {
                iv.setBackgroundResource(R.drawable.selector2);
            }
        }

    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode,resultCode,data);
    }

}
